package com.controller.purchase;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.model.purchase.PurchaseSixCostsOrdersModel;
import com.service.purchase.PurchaseSixCostsOrdersService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.DateUtils;
import com.common.http.HttpResult;


/**
 *
 */
@Controller("sixCostsOrdersController")
@RequestMapping(value = "/api")
public class PurchaseSixCostsOrdersController {
    static final Logger logger = LoggerFactory.getLogger(PurchaseSixCostsOrdersController.class);

    @Autowired
    PurchaseSixCostsOrdersService sixCostsOrdersService;


    /**
     * 查询列表
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/selectList", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult selectList(@RequestParam Map<String, Object> map) {
        return sixCostsOrdersService.selectList(map);
    }

    /**
     * 查询详情
     *
     * @param
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/selectInfor", method = {RequestMethod.GET})
    @ResponseBody
    public HttpResult selectInfor(@RequestParam String purId) {
        return sixCostsOrdersService.selectInfor(purId);
    }

    /**
     * 保存
     *
     * @param
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/save", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult save(@RequestBody PurchaseSixCostsOrdersModel sixCostsOrdersModel) {
        return sixCostsOrdersService.save(sixCostsOrdersModel);
    }

    /**
     * 提交
     *
     * @param
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/commit", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult commit(@RequestBody PurchaseSixCostsOrdersModel sixCostsOrdersModel) {
        return sixCostsOrdersService.commit(sixCostsOrdersModel);
    }

    /**
     * 删除
     *
     * @param
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/delete", method = {RequestMethod.DELETE})
    @ResponseBody
    public HttpResult delete(@RequestParam String purId) {
        return sixCostsOrdersService.delete(purId);
    }

    /**
     * 撤回
     *
     * @param
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/back", method = {RequestMethod.GET})
    @ResponseBody
    public HttpResult back(@RequestParam String purId) {
        return sixCostsOrdersService.back(purId);
    }

    /**
     * 导出
     *
     * @param map
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "purchase/sixCosts/export")
    public void export(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("采购订单-" + DateUtils.getCurrentDate(), "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        sixCostsOrdersService.export(map, response);

    }

    /**
     * 更新原始交货单各费用的可选状态
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "purchase/sixCosts/updateDeliveryOrdersStatus", method = {RequestMethod.POST})
    @ResponseBody
    public HttpResult updateDeliveryOrdersStatus(@RequestParam Map<String, String> map) {
        return sixCostsOrdersService.updateDeliveryOrdersStatus(map);
    }
}
